#include <bits/stdc++.h>
using namespace std;
int T;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        int n,m,l,V,p[100005],flag[100005],d[100005],v[100005],a[100005],ans1 = 0,ans2 = 0,bucket[100005];
        memset(flag,0,sizeof(flag));
        memset(bucket,0,sizeof(bucket));
        scanf("%d%d%d%d",&n,&m,&l,&V);
        for(int i = 1;i <= n;i++) scanf("%d%d%d",&d[i],&v[i],&a[i]);
        for(int i = 1;i <= m;i++) scanf("%d",&p[i]);
        for(int i = 1;i <= n;i++){
            int t1,t2;
            if(a[i] == 0){
                if(v[i] > V){
                    t1 = d[i];
                    t2 = l;
                } else {
                    continue;
                }
            } else {
                double temp = (double)(V*V-v[i]*v[i])/(2*a[i]);
                int tmp = ceil(temp);
                if(a[i] < 0){
                    t1 = d[i];
                    t2 = d[i]+tmp-1;
                } else {
                    t1 = d[i]+tmp+1;
                    t2 = l;
                }
            }
            int fg = 0;
            for(int j = 1;j <= m;j++){
                if(t1 <= p[j] && p[j] <= t2){
                    flag[j]++;
                    if(fg == 0) bucket[j]++;
                    fg = 1;
                }
            }
            if(fg) ans1++;
        }
        for(int i = 1;i <= m;i++){
            if(bucket[i] > 0){
                ans2++;
            }
        }
        printf("%d %d\n",ans1,m-ans2);
    }
    return 0;
}
